<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link href="${ctx }/resources/css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx }/resources/css/H-ui.admin.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx }/resources/css/style.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx }/resources/lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>活动管理</title>
</head>

<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 活动管理 <span
        class="c-gray en">&gt;</span> 活动列表 <a class="btn btn-success radius r mr-20"
                                              style="line-height:1.6em;margin-top:3px"
                                              href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="pd-20">
    <shiro:hasPermission name="sys:user:add"> </shiro:hasPermission>
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <a class="btn btn-primary radius" href="javascript:;"
               onclick="add_activity('添加活动','${ctx}/activity/toAddActivity','1000','500')"><i class="Hui-iconfont">
                &#xe600;</i> 添加活动</a>
            <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">
                &#xe6e2;</i> 批量删除</a>
        </span>
    </div>

    <table class="table table-border table-bordered table-hover table-bg">
        <thead>
        <tr>
            <th scope="col" colspan="6">活动管理</th>
        </tr>
        <tr class="text-c">
            <th style="width:18px;padding-right:6px;"><input id='checkall' type='checkbox'
                                                             value='true'/></th>
            <th width="40">ID</th>
            <th width="200">活动标题</th>
            <th width="70">活动内容</th>
            <th width="70">开始时间</th>
            <th width="70">结束时间</th>
            <th width="70">状态</th>
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${data }" var="d">
            <tr class="text-c">
                <td><input name='ids' type='checkbox' value=${d.id}></td>
                <td>${d.id}</td>
                <td>${d.title }</td>
                <td>${d.content }</td>
                <td>${d.begin_time}</td>
                <td>${d.end_time}</td>
                <c:if test="${d.status==0}">
                    <td class="td-status"><span class="label radius">禁用</span></td>
                </c:if>
                <c:if test="${d.status==1}">
                    <td class="td-status"><span class="label label-success radius">启用</span></td>
                </c:if>
                <c:if test="${d.status==0}">
                    <td class="td-manage">
                        <a style="text-decoration:none" onClick="activity_start('${d.id}')" href="javascript:;"
                           title="启用">
                            <i class="Hui-iconfont">&#xe631;</i></a>
                        </a>
                    </td>
                </c:if>
                <c:if test="${d.status==1}">
                    <td class="td-manage">
                        <a style="text-decoration:none" onClick="activity_stop('${d.id}')" href="javascript:;"
                           title="禁用">
                            <i class="Hui-iconfont">&#xe631;</i></a>
                        </a>
                    </td>
                </c:if>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<script type="text/javascript" src="${ctx }/resources/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx }/resources/js/H-ui.js"></script>
<script type="text/javascript" src="${ctx }/resources/js/H-ui.admin.js"></script>
<script type="text/javascript">
    $('.table-sort').dataTable({
        "aaSorting": [[1, "desc"]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
            {"orderable": false, "aTargets": [0, 8]}// 制定列不参与排序
        ]
    });

    /*添加用户*/
    function add_activity(title, url) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }
    function change_role(title, url, w, h) {
        layer_show(title, url, w, h);
    }

    $(function () {
        $('#checkall').click(function () {
            var items = document.getElementsByName('ids');
            for (var i = 0; i < items.length; i++) {
                items[i].checked = this.checked;
            }
        });
    })
    function datadel() {
        var ids = [];
        $("input[name=ids]:checked").each(function () {
            ids.push($(this).val());
        });
        if (ids.length == 0) {
            alert("请选择要删除的活动");
            return;
        }
        var url = "${ctx }/activity/deletes";
        $.ajax(
                {
                    type: "post",
                    url: url + "/" + ids,
                    success: function (data) {
                        if (data == 'success') {
                            alert("删除成功");
                            window.location.reload();
                            $("input[name=ids]").each(function () {
                                $(this).removeAttr("checked");
                            });
                        }
                    }
                }
        );
    }

    function activity_stop(id) {
        $.ajax({
            url: "${ctx}/activity/disable/" + id,
            type: 'post',
            data: null,
            success: function (data) {
                window.location.reload();
            }
        })
    }
    function activity_start(id) {
        $.ajax({
            url: "${ctx}/activity/enable/" + id,
            type: 'post',
            data: null,
            success: function (data) {
                window.location.reload();
            }
        })
    }
</script>
</body>
</html>
